<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script type="text/javascript"
	src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
	<script type="text/javascript" src="js/jquery-3.1.0.js"></script>
<!-- 引入样式 -->
<link rel="stylesheet"
	href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
<!-- 引入组件库 -->
<script src="https://unpkg.com/element-ui/lib/index.js"></script>
<script type="text/javascript" src="js/axios.js"></script>
<script type="text/javascript" src="js/qs.js"></script>
<style type="text/css">
.lisdiv{
   height: 35px;
   line-height: 35px;
   border-bottom: 1px #ccc dashed;
}
.spand{
    margin-right:20px;
    margin-left: 20px;
}
.inputse{
margin-right: 5px;
}
.funsub{
   width: 250px;
   margin: 5px;
   margin: 0 auto;
   background: #ccc
}
</style>

</head>

<body class="fixed-left modal-open" style="padding-right: 16px;">
		<div class="modal-dialog" id="basepop_popview_first_child"
			style="width: 700px;">
			<div class="modal-content">
				<div class="modal-header">

					<h4 class="modal-title" id="basepop_popview_title">批量共享</h4>
				</div>
				<div class="modal-body" id="basepop_popview_body">
					<h4>选择共享的目标用户</h4>
				<div id="ids" style="height: 500px; width: 100%">
					<from id="fromse">
				    	<c:forEach items="${userall}" var="userall">
				    	 <li class="lisdiv">
				    	 <span id="${userall.use_id}" class="spand">${userall.use_name}</span>
				    	 <input type="hidden" value="${userall.use_id}" name="inpused">
				    	   <input type="checkbox" name="apiContent" value="可读" class="inputse">读
					       <input type="checkbox" name="apiContentse" value="可写" class="inputse">写
				    	  </li>
				    	  </c:forEach>
				    	<input type="button"  name="" value="提交" onclick="funsub();" class="funsub"/>
				    	  
				    	</from>
				    	
				    	
				    	<script type="text/javascript">
				    	function funsub() {
				    		var inpused=document.getElementsByName("inpused");
				    		//alert(inpused);
				    		var inpuArray = inpused.length;
							var box=document.getElementsByName("apiContent");
							//alert(box+"          读");
							var boxse=document.getElementsByName("apiContentse");
						//	alert(boxse+"               写");
							var sm = new Array();
							for(var i=0;i<inpuArray;i++){
								var apiContentStr="";
								if(box[i].checked == true&&boxse[i].checked == false){
								
									apiContentStr=inpused[i].value+","+box[i].value;
									sm.push(apiContentStr);
								}else if(boxse[i].checked == true&&box[i].checked == false){
										apiContentStr =inpused[i].value+","+boxse[i].value;
										sm.push(apiContentStr);
									}else if(boxse[i].checked == true&&box[i].checked == true){
										apiContentStr=inpused[i].value+","+box[i].value+boxse[i].value;
										sm.push(apiContentStr);
									}								
								} 
							
							//alert(sm);
							
							if(sm.length<=0){
								alert("请选择要分享的用户");
							}else{
								 $.ajax({  
									    type : 'POST',  
									    url:'/selsefrom',  
									    contentType : "application/json" ,
									    data : JSON.stringify(sm), 
									    success : function(data) {
									    	parent.document.location.reload();
									    	//alert(data);
									    	if(data==1){
									    		alert("分享成功");
									    	}else if(data==2){
									    		alert("已存在相同的分享记录将不会重复添加");
									    	}else if(data==0){
									    		//alert("已存在相同的分享记录将不会重复添加");
									    	}
									    }  
									}); 
								 
							}
							/* $.ajax({
								url : "/selsefrom",
								data : JSON.stringify(sm),
								type : "post",
								dataType : "json",
								async : true,
								cache : false,
								processData : false,
								contentType : false,
								success:function(result) {
									alert(result);
									if (result == "0") {															
								
								}
							}
							}); */
				    	}
						</script>
						<!-- 	
						
							$.ajax({
								url : "http://localhost:8089/selsefrom",
								data : new FormData($('#theForm')[0]),
								type : "post",
								dataType : "json",
								async : true,
								cache : false,
								processData : false,
								contentType : false,
								success:function(result) {
									alert(result);
									if (result == "0") {															
								
								}
							}
							});
							
							 	apiContentStr = apiContentStr.substring(0, apiContentStr.length-1);
							$('#fromse').attr('action', '/selsefrom?apiContentStr='+apiContentStr);
							$('#fromse').submit();
							}	
						
							
				    	$.ajax({
				    		url : "user/selsefrom",
				    		data : {
				    		"datas" :sm
				    		},
				    		dataType : "json",
				    		success : function(data) {
				    		alert(data);
				    		},
				    		async : false
				    		});  -->
						
				    	 
				    	
				    	
				    
						<!-- <el-form ref="anniForm" class="demo-ruleForm" :model="anniForm"
							label-width="80px" :inline="true"> 
				    	<ul v-for="(item, index) in restaurants">	 -->
				    	
				    	
				    	<%-- </c:forEach>
				    	
				    				    	
					    	<li>
					    	<el-form-item label="">
					    	<!-- <el-input v-show="false" v-model="item.use_id"></el-input> -->
					    	<span>{{item.use_name}} </span> 
					    	</el-form-item>					       
					       <input type="checkbox" id="runoob" value={{item.use_name}} v-model="checkedNames">读
					       <input type="checkbox" id="runoobs" value={{item.use_name}} v-model="checkedNames">写
					     --%>
					    
						   <!--   <el-form-item label=""> 
						     <el-checkbox-group
						      v-model="checkedEquipments[item.use_id]"
						      @change="handleChange(item.use_id)"> 
						     <el-checkbox  label="读"  v-model="checkedNames"></el-checkbox>
						     <el-checkbox label="写"  v-model="checkedNames"></el-checkbox> 
							</el-checkbox-group>
							</el-form-item> -->
							<!-- {{checkedNames}} -->
							
							
						<!-- </li>							
					    </ul>
					    
			
						<el-form-item> <el-button
							@click="resetForm('anniForm')">重置</el-button> <el-button
							type="primary" @click="submitForm('anniForm')">立即创建</el-button>					
							 </el-form-item>
						</el-from>
					</div>
					<script>
								var vm=new Vue({
									el:"#ids",
									data(){
										
								return{
									checkedEquipments:[],
									restaurants:[],									
								    anniForm:{	
								    	
								   }
								}										
									},
									methods: {	
										/* handleChange () {
									        this.checkEquipArr = []
									        var arr = this.checkedEquipments
									        for (var i = 0; i < arr.length; i ++) {
									          var equipment = arr[i]
									          if (equipment.length > 0) {
									            var obj = {
									              id: this.equipments[i].id,
									              equips: []
									            }
									            for (var j = 0; j < equipment.length; j++) {
									              obj.equips.push(equipment[j])
									            }
									            this.checkEquipArr.push(obj)
									          }
									        }
									        console.log(this.checkEquipArr +"    checkEquipArr");
									        console.log(this.checkedEquipments +"     checkedEquipments");
									      }, */
									      
										submitForm(anniForm) {										
								    	//验证方法
								        this.$refs[anniForm].validate((valid) => {
								          if (valid) {
								        	  //post提交数据
								           	axios.post("/anniForm",
								           			//参数转换
								           			Qs.stringify(this.anniForm,{arrayFormat: 'brackets'})
								           		//	params:
								           			//ajax请求成功的回调函数
								           			).then(function(v){
								           		///-	console.log("回调成功，获取了服务器端返回的值v");
								           			alert(v.data.typese);
								           			//console.log(v);
								           	}).catch(function(){
								           		//alert("存在未完成的订单");
								           	});							        	  							        	  
								          } else {
								            console.log('error submit!!');
								            return false;								            
								          }
								         
								        });																						
										},
										resetForm(formName) {
											this.$refs[formName].resetFields();
										}
										
									},mounted() {
										var iosnn=this;
										//post提交数据
										axios.post("/selectcustuser",
											//参数转换
											Qs.stringify(this.anniForm, {
												arrayFormat: 'brackets'
											})		
										).then(function(v) {
											//vm.restaurants=v.data;
											// console.log(vm.restaurants);
											 iosnn.restaurants = v.data;
											
											 //console.log(iosnn.restaurants);
										    // console.info(v.data);
										}).catch(function(e) {  
											alert("出错了"+e);
										});
									
									}
								});
								
							</script>
				
				
				  -->
				 
				 
				 
				</div>
			</div>
		</div>
	</div>
</body>

</html>